package com.li.druid.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.li.druid.entity.Student;
import com.li.druid.mapper.IStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private IStudentMapper studentMapper;

    @RequestMapping("/test")
    public void test(){
        Student student  = new Student();

    }

    /**
     * 分页查询
     * @param pageNo
     * @param pageSize
     * @param student
     */
    @RequestMapping("/page")
    public void page(@RequestParam Integer pageNo,@RequestParam Integer pageSize,Student student){

        student.setGradeId(2);
        // 添加查询条件
        QueryWrapper<Student> query = new QueryWrapper<>();
        // 直接通过实体类进行精确查询
        query.setEntity(student);
        // 获取查询列表
        Page<Student> page = (Page<Student>) studentMapper.selectPage(pageNo,pageSize,query);
        List<Student> list = page.getRecords();
        list.forEach(stu -> {
            System.out.println(stu.getName());
        });
    }
}
